#!/bin/bash
#
# Init file for rtsp monitor daemon
#
# chkconfig: 45 95 15
# description: Rtsp Monitor daemon
#
# processname: transcoded
# pidfile: /var/run/transcoded.pid

# source function library
. /etc/rc.d/init.d/functions

RETVAL=0
prog="status-monitord"

# Some functions to make the below more readable

USER=dss-admin
BIN=/usr/local/bin/status-monitor
PROG=$BIN/status-monitord
LOG=/var/log/status-monitor.log
PID_FILE=/var/run/status-monitord.pid
LOCK_FILE=/var/lock/subsys/status-monitord

start()
{
	echo -n $"Starting $prog: "
	su $USER -c "echo `date` \" Starting\" >>$LOG"
	daemon --user $USER "$PROG" "$OPTIONS 2>&1 >>$LOG &" && success || failure
	myPid=`ps -fe|grep $PROG|egrep -v grep|awk '{print $2}'`
	RETVAL=$?
	if [ "$RETVAL" = 0 ]
	    then touch $LOCK_FILE
	    echo $myPid >$PID_FILE
	fi
	echo
}

stop()
{
	echo -n $"Stopping $prog: "
	if [ -n "`pidfileofproc $PROG`" ] ; then
	    killproc $PROG -TERM
	else
	    failure $"Stopping $prog"
	fi
	RETVAL=$?
	[ "$RETVAL" = 0 ] && rm -f $LOCK_FILE
	echo
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	status)
		status $PROG
		RETVAL=$?
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|status}"
		RETVAL=1
esac
exit $RETVAL
